package com.china08.yxyapi.api.temp;

import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.service.sws.sws.impl.SwsWebsiteStatisticsMGImpl;
import com.china08.yxyapi.util.DateUtils;

@CrossOrigin
@RestController
public class SwsWebsiteTongjiController2 {

    private static final Logger log = LoggerFactory.getLogger(ResourceAndWeikeStatisticalController.class);
    @Autowired
    private SwsWebsiteStatisticsMGImpl swsStatisticsMGImpl;

    /**
     * 2017-05-05/2017-05-06
     * 
     * @param request
     * @param response
     * @param begin
     * @param end
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/api_yw/temp/sws/website/tongji/date/{begin}/{count}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object process(HttpServletRequest request, HttpServletResponse response,
            @PathVariable(value = "begin") Integer begin, @PathVariable(value = "count") Integer count)
            throws ParseException {
        log.info("====网站MQ开始===");
        log.info("开始时间： " + begin);
        log.info("结束时间： " + count);
        StringBuffer str = new StringBuffer();
        if (begin < 10000000 || count < 0) {
            str.append("开始时间不能大于结束时间,并且格式为yyyyMMdd,查询天数不能为负数");
            return str;
        }
        for (int i = count; i >= 0; i--) {
            Integer day = DateUtils.formatDate4(DateUtils.subtractDay(DateUtils.formatStrDate4(begin), i));
            swsStatisticsMGImpl.getZiXunCount(day);
            swsStatisticsMGImpl.getLanMuCount(day);
            swsStatisticsMGImpl.getLanMuMessage(day);
            swsStatisticsMGImpl.getKaiTongSchoolMonth(day);// 统计month之前,先补全
            swsStatisticsMGImpl.getKaiTongSchoolTotal(day);// 统计total之前,先补全
        }
        log.info("===========结束========");
        return str;
    }
}
